﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)
        {
            var name = this.textBox1.Text;
            var pwd = this.textBox2.Text;
            if (name.Equals("")||pwd.Equals(""))
            {
                MessageBox.Show("用户名和密码不能为空");
            }
            else 
            {
                var sql = string.Format("select*from Users where Username='{0}'and Password='{1}'",name,pwd);
                DbHelper db = new DbHelper();
                var res = DbHelper.GetDataTable(sql);
                if (res.Rows.Count==1)
                {
                    MessageBox.Show("登录成功");
                    MainForm mainForm = new MainForm();
                    this.Hide();
                    mainForm.Show();

                }
                else 
                {
                    MessageBox.Show("用户名或密码错误");
                }
            
            }
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            RegisterForm register = new RegisterForm();
            register.Show();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
